<?php include'./general/general.php'; ?>
<?php
	class OnlineStore{
			private $DBConnect = NULL;
			private $storeID = "";
			private $inventory = array();
			private $shoppingCart = array();
			private $email = "";
			private $instock = 0;
			//private $itemsTotal = 0;
			
			function __construct(){
					include("./database/inc_OnlineStoreDB.php");
					$this->DBConnect = $DBConnect;
					//echo "<p>Hello DB</p>";
				}
			function __destruct(){
					if(!$this->DBConnect->connect_error)
						$this->DBConnect->close();
				}
			function __wakeup(){
					include("./database/inc_OnlineStoreDB.php");
					$this->DBConnect = $DBConnect;
				}
			
			public function setStoreID($storeID){
				if($this->storeID != $storeID){
					$this->storeID = $storeID;
					$SQLString = "SELECT * FROM inventory WHERE storeID = '" .$this->storeID ."'";
					$QueryResult = @$this->DBConnect->query($SQLString);

					if($QueryResult === FALSE){
						$this->storeID = "";
						throw new Exception("Error code: ".$DBConnect->connect_errno.": ".$DBConnect->connect_error."", 1);
					}
					else{
						$this->inventory = array();
						while(($Row = $QueryResult->fetch_assoc()) !== NULL){
							$this->inventory[$Row['productID']] = array();
							$this->inventory[$Row['productID']]['image_file'] = $Row['image_file'];
							$this->inventory[$Row['productID']]['description'] = $Row['description'];
							$this->inventory[$Row['productID']]['price'] = $Row['price'];
							$this->inventory[$Row['productID']]['stock'] = $Row['stock'];
							$this->shoppingCart[$Row['productID']] = 0;
						}
					}
				}
			}
			public function getStoreInformation(){
					$retval = FALSE;
					if($this->storeID != ""){
						$SQLString = "SELECT * FROM store_info " .
							" WHERE storeID = '" .
							$this->storeID . "'";
						$QueryResult = @$this->DBConnect->query($SQLString);
						if($QueryResult !== FALSE){
								$retval = $QueryResult->fetch_assoc();
							}
					}
						return($retval);
				}
				public function getInventoryInformation(){
					$retval = FALSE;
					if($this->storeID != ""){
						$SQLString = "SELECT * FROM inventory " .
							" WHERE storeID = '" .
							$this->storeID . "'";
						$QueryResult = @$this->DBConnect->query($SQLString);
						if($QueryResult !== FALSE){
								$retval = $QueryResult->fetch_assoc();
							}
					}
						return($retval);
				}
				
			public function getProductList(){
				//echo "Inside getProductList";
					$retval = FALSE;
					$subtotal = 0;
					$totalInCart = 0;
					//$availstock = 0;
					if(count($this->inventory) > 0){
						echo "<div class='container'>";
						foreach ($this->inventory as $ID => $Info) {
							# code...
							$instock = $Info['stock'];
							echo "<div class='row'>";
							echo "<div class='span10'>";
							/*	echo "<ul class='thumbnails'>";
									echo "<li class='span4'>";
									echo "<div class='thumbnail'>";
									//echo "<p>".htmlentities($Info['name'])."</p>";
									echo "<img src='".$Info['image_file']."' alt='product image'/>";									
									echo "<p>".htmlentities($Info['description'])."\n";
									echo "<br/>\n";
									printf("Price: R%.1f", $Info['price']);										
									
									//echo "".$this->shoppingCart[$ID]."\n"; #incart
									echo "<br/>\n";
									echo "<button class='btn btn-success'><a href='".
									$_SERVER['SCRIPT_NAME'].
									"?PHPSESSID=". session_id() .
									"&ItemToAdd=$ID'>Add ".
									" Item</a></button>";
									$totalInCart += $this->shoppingCart[$ID];
									//$numOfItems += $this->shoppingCart[$ID];
									$instock = $instock - $this->shoppingCart[$ID];
									//echo "<br/>\n";	
									if($totalInCart >= $Info['stock']){
										echo "<p>OUT OF STOCK</p>";
										//return FALSE;
									}else{
										//echo "In Stock: Available\n";
										echo "<br/>\n";
										echo "Available items: {$instock}\n";
									}
									//echo "<p>{$instock}</p>";
									echo "</p>";
									echo "</div>";
									echo "</li>";

								echo "</ul>";
								*/
								echo "<ul class='media-list'>";
								  echo "<li class='media'>";
								    echo "<a class='pull-left' href='#'>";
								      echo "<img class='img-polaroid' src='".$Info['image_file']."'>";
								    echo "</a>";
								    echo "<div class='media-body'>";
								    echo "<p>".htmlentities($Info['description'])."\n";	
								      printf("Price: R%.1f", $Info['price']);
								     // echo "<h4 class='media-heading'>".htmlentities($Info['name'])."</h4>";
								      //echo "<p>".htmlentities($Info['name'])."</p>";									      						 
								     echo "<!-- Nested media object -->";
								      echo "<div class='media'>";
								        
									//echo "<br/>\n";	
									if($totalInCart >= $Info['stock']){
										echo "<p>OUT OF STOCK</p>";
										//return FALSE;
									}else{
										//echo "In Stock: Available\n";
										//echo "<br/>\n";
										echo "<button class='btn btn-success'><a href='".
									$_SERVER['SCRIPT_NAME'].
									"?PHPSESSID=". session_id() .
									"&ItemToAdd=$ID'>Add ".
									" Item</a></button>";
									$totalInCart += $this->shoppingCart[$ID];
									//$numOfItems += $this->shoppingCart[$ID];
									$instock = $instock - $this->shoppingCart[$ID];
										echo "<p>Available items: {$instock}</p>\n";
									}
								     echo "</div>";
								    echo "</div>";
								  echo "</li>";
								echo "</ul>";

							echo "</div>";	
							echo "</div>";
						}

						/*echo "<div class='span2'>";
						echo "<p><a href='cart.php'> View Busket</a></p>";	
						echo "<p><label><i class='icon-shopping-cart btn-large'></i>Items:&nbsp;&nbsp;&nbsp;{$totalInCart}</label></p>";
						echo "</div>";*/
						echo "<a class='btn btn-success btn-large' href='cart.php'><i class='icon-shopping-cart icon-large'></i>Items:&nbsp;&nbsp;&nbsp;{$totalInCart}| View Cart</a>";
						/*echo "<table>\n";
						echo "<tr><td><a href='cart.php'> View Busket</a></td></tr>\n";
						echo "<tr><td><label><i class='icon-shopping-cart btn-large'></i>Items:&nbsp;&nbsp;&nbsp;{$totalInCart}</label></td></tr>";
						echo "</table>";*/
						
							
						echo "</div>";
						echo "</div>";
							
							$retval = TRUE;
						}
					return($retval);
				}

				public function getAllProductList(){
				//echo "Inside getProductList";
					$retval = FALSE;
					$subtotal = 0;
					$totalInCart = 0;
					if(count($this->inventory) > 0){
						echo "<div class='container'>";
						foreach ($this->inventory as $ID => $Info) {
							# code...
							echo "<div class='row'>";
							echo "<div class='span8'>";
								/*echo "<ul class='thumbnails'>";
									echo "<li class='span3'>";
									echo "<div class='thumbnail'>";
									//echo "<p>".$Info['name']."</p>";
									echo "<img src='".$Info['image_file']."' alt='product image'/>";									
									echo "<p>".htmlentities($Info['description'])."\n";
									echo "<br/>\n";
									printf("Price: R%.1f", $Info['price']);
									//echo "<p>".$this->shoppingCart[$ID]."</p>\n";
									//echo "<br/>\n";
									//echo "<button class='btn btn-success'><a href='".
									//$_SERVER['SCRIPT_NAME'].
									//"?PHPSESSID=". session_id() .
									//"&ItemToAdd=$ID'>Add ".
									//" Item</a></button>";
									//$totalInCart += $this->shoppingCart[$ID];
									echo "</p>";
									echo "</div>";
									echo "</li>";
								echo "</ul>";*/

							echo "<ul class='media-list'>";
								  echo "<li class='media'>";
								    echo "<a class='pull-right' href='#'>";
								      echo "<img class='img-polaroid' src='".$Info['image_file']."'>";
								    echo "</a>";
								    echo "<div class='media-body'>";
								     // echo "<h4 class='media-heading'>".htmlentities($Info['name'])."</h4>";
								      //echo "<p>".htmlentities($Info['name'])."</p>";									      						 
								     echo "<!-- Nested media object -->";
								      echo "<div class='media'>";
								        echo "<p>".htmlentities($Info['description'])."\n";	
								      printf("Price: R%.1f", $Info['price']);
								     echo "</div>";
								    echo "</div>";
								  echo "</li>";
								echo "</ul>";

							echo "</div>";	
							echo "</div>";						

						}
						echo "</div>";
							
							$retval = TRUE;
						}
					return($retval);
				}
				public function getAllProductListSlides(){

					$retval = FALSE;
					$subtotal = 0;
					$totalInCart = 0;
					if(count($this->inventory) > 0){
						
						foreach ($this->inventory as $ID => $Info) 
						{

					echo"<div class='row' id ='main-content'>  ";
					echo"<div  class='span8' style='float-left:100px'>";
					    echo"<div id='slider' class='carousel slide' >";
					        echo"<div class='carousel-inner'>";
					            echo"<div class='item active'>";
					               echo" <img src='".$Info['image_file']."'>";
					                 echo"   <div class ='carousel-caption'>";
					                 echo "<p>".htmlentities($Info['description'])."\n";
									echo "<br/>\n";
									printf("Price: R%.1f", $Info['price']);
					                 echo "   </div>";
					                echo "  </img>  ";
					           echo "   </div>";
					          
					      echo "   </div>";
					       echo " <a class='left carousel-control' href='#slider' data-slide='prev'>&lsaquo;</a>";
					        echo "<a class='right carousel-control' href='#slider' data-slide='next'>&rsaquo;</a>";
					   echo "  </div>";
					echo "</div>";
					echo "</div>"; 
						echo "</div>"; 
					}
					
							
							$retval = TRUE;
				}
					return($retval);
				}
		public function showCart() 
		{
					//-----------------------------------------------------------------------------------------------
					$Row = NULL;
				$subtotal = 0;
				$retval = FALSE;
				$totalInCart = 0;
					
					echo "<table width='100%' border='1'>\n";
					echo "<tr><th>Product</th>"
					. "<th>Description</th>"
					. "<th>Price Each</th>"
					. "<th># in Cart</th>"
					. "<th>Total Price</th>"
					. "<th>&nbsp;</th>"
					. "<th>&nbsp;</th>"
					. "</tr>\n";
				
					foreach($this->shoppingCart as $prodInfo => $quantity) 
					{
				
						if($quantity > 0) 
						{
							
							$Row = $this->getProdInfo($prodInfo);
							$instock = $Row['stock'];
						
							echo "<tr><td>" . htmlentities($Row['name'])
								. "</td>\n";	
							echo "<td>" . htmlentities($Row['description'])
								. "</td>\n";
							printf("<td class='currency'>R%.2f</td>\n",
									$Row['price']);		
							echo "<td style='text-align: center'>" . htmlentities($quantity)
								. "</td>\n";
							printf("<td class='currency'>R%.2f</td>\n",
									$Row['price'] * $quantity);
							echo "<td><a href='" . 
									$_SERVER['SCRIPT_NAME'] .
									"?PHPSESSID=" . session_id() .
									"&ItemToRemove=$prodInfo'>Remove Item</a></td>\n";	

							echo "<td><a href='" .
								$_SERVER['SCRIPT_NAME'] .
									"?PHPSESSID=" . session_id() . 
									"&RemoveAll=$prodInfo'>Remove All</a></td></tr>\n";		
							$subtotal += $Row['price'] * $quantity;		
							$totalInCart -= $quantity;
							$instock += $quantity;

							$retval = TRUE;
							
						}					
					}
					/*if($Row == NULL)
					{
						echo "<h1>No Items In Your Cart</h1>";
					}*/
					

					
					echo "<tr class='subtotal'><td colspan='4'>Subtotal</td>\n";
					printf("<td class='currency'>R%.2f</td>\n",
						$subtotal);
					echo " <td></td>\n";
					echo "<td><a href='" .$_SERVER['SCRIPT_NAME'] .
						"?PHPSESSID=" . session_id() .
						"&EmptyCart=TRUE'>Empty Cart/Cancel Order</a></td></tr>\n";					
					echo "</table>";

					if($totalInCart == 0){
						echo "<p align='center'><h1>No items selected!</h1></p>\n\n";	
						//return FALSE;
					}
					echo "<br>\n";
				//	echo "<p><a href='checkout.php?PHPSESSID=".session_id()."&CheckOut=".$this->storeID."'>Continue to Checkout</a></p>";
					echo "<a class='btn btn-success' href='checkout.php?PHPSESSID=".session_id()."&CheckOut=".$this->storeID."'><i class='icon-shopping-cart icon-large'></i> Checkout</a>";
					//echo "<a href='cart.php'>Back to Edit Selected Items</a>";

								/*echo "<p><button class='btn btn-info' pull-center><a href=' ".
										$_SERVER['SCRIPT_NAME'].
										"?PHPSESSID=".session_id().
										"&EmptyCart=TRUE'>Empty ".
										" Cart</a></button>\n</p>";*/
					
				
			}//end showcart

			public function getProdInfo($prodID) 
			{
				$SQLstring = "SELECT * FROM inventory " . 
					"where productID = '" . 
						$prodID . "'";
				$QueryResult = @$this->DBConnect->query($SQLstring);
				if($QueryResult === FALSE)
					exit("<p>Error Obtaining Product Info!</p>");
				else {
					$Row = $QueryResult->fetch_assoc();
					if($Row !== NULL) {
						return($Row);
					}
				}			
			}//end getProdInfo

			public function updateStock($prodID, $items_avail){
				$SQLstring = "UPDATE inventory SET stock = $items_avail WHERE productID = '$prodID'";
				$QueryResult = @$this->DBConnect->query($SQLstring);
				if($QueryResult === FALSE)
					exit("<p>Error updating Inventory table</p>");				
			}

			public function confirmOrder() 
			{	
				$retval = FALSE;
				$subtotal = 0;
				$totalI = 0;
				$totalP = 0;

				if(count($this->inventory) > 0){
					echo "<div class='container'>";
							echo"<table width= '100%' border='1'>\n";
							echo"<tr><th>Number of Items</th>".
							"<th>Total Price</th></tr>\n";
					foreach ($this->inventory as $ID => $Info) {
						# code...
						if($this->shoppingCart[$ID] != 0){
							$totalI += $this->shoppingCart[$ID];
							$totalP += $Info['price'] * $this->shoppingCart[$ID];
							
									//echo "&nbsp;<td class= 'currency'>".$this->shoppingCart[$ID]."</td>\n";
									//printf("<td class= 'currency'>R%.2f</td>\n", $Info['price'] * $this->shoppingCart[$ID]);
									/*echo "<td><a href='" . $_SERVER['SCRIPT_NAME'].
									"?PHPSESSID=" . session_id() .
									"&ItemToRemove=$ID'>Remove " .
									" Item</a></td>\n";*/
									//$subtotal += ($Info['price'] * $this->shoppingCart[$ID]);
									//$totalInCart -= $this->shoppingCart[$ID];
									//$subtotal += ($Info['price'] * $this->shoppingCart[$ID]);
									//echo "</div>";
									}
								}
								echo "<tr><td align='center'>{$totalI}</td>\n";
							printf("<td class= 'currency'>R%.2f</td></tr>\n", $totalP);
							//echo "<tr><td colspan= '3'>Subtotal</td>\n";
							//printf("<td class= 'currency'>R%.2f</td>\n", $subtotal);
							/*echo "<td><a href='" .
							$_SERVER['SCRIPT_NAME'] .						
							"?PHPSESSID=" . session_id() .
							"&EmptyCart=TRUE'>Empty ".
							" Cart</a></td></tr>\n";*/
							echo"</table>";
							//echo "</div>";

					
					echo "<div class='span4'>";
					echo "<p><a href='checkout.php?PHPSESSID=".session_id()."&CheckOut=".$this->storeID."'>Continue to Checkout</a></p>";
					echo "<a href='cart.php'>Back to Edit Selected Items</a>";
					//echo "</div>";

					//echo "<label><i class='icon-shopping-cart icon-small'></i>&nbsp;{$totalInCart}</label>";
					//echo "</div>";
					echo "</div>";
				}

					$retval = TRUE;
				
				return($retval);
			}
			
			private function addItem(){
                $prodID = $_GET['ItemToAdd'];
                if(array_key_exists($prodID, $this->shoppingCart))
                    $this->shoppingCart[$prodID] += 1;					
			}
				
			private  function addOne(){
				//$prodID = $_GET['AddOne'];
					
				}
			private function removeItem(){
				$prodID = $_GET['ItemToRemove'];
				if (array_key_exists($prodID, $this->shoppingCart)) {
					if($this->shoppingCart[$prodID] > 0)
						$this->shoppingCart[$prodID] -= 1;
				}
					
			}
			private function emptyCart(){
				foreach ($this->shoppingCart as $key => $value) {
					$this->shoppingCart[$key] = 0;
				}
			}
			private function removeAll()
			{
				//re-do...?
				$prodID = $_GET['RemoveAll'];
				if(array_key_exists($prodID, $this->shoppingCart)){
					if($this->shoppingCart[$prodID] > 0)
						$this->shoppingCart[$prodID] = 0;
				}
					
			}
			public function processUserInput(){
					if(!empty($_GET['ItemToAdd']))
						$this->addItem();
					if(!empty($_GET['AddOne']))
						$this->addOne();
					if(!empty($_GET['ItemToRemove']))
						$this->removeItem();
					if(!empty($_GET['EmptyCart']))
						$this->emptyCart();
					if(!empty($_GET['RemoveAll']))
						$this->removeAll();
				}
				
				public function getProductInfo($prodID) 
				{
					$SQLstring = "SELECT * FROM inventory " . 
							"where productID = '" . 
					$prodID . "'";
					$QueryResult = @$this->DBConnect->query($SQLstring);
					if($QueryResult === FALSE)
						exit("<p>Error Obtaining Product Info!</p>");
					else{
						$Row = $QueryResult->fetch_assoc();
						if($Row !== NULL){
							return($Row);
						}
					}	
				}

				public function getEmail(){

				}
		
			public function checkout(){
				$productOrdered = 0;
				$date = date('Y/m/d H:i:s');
				$product_id = "";
				//echo "<p><strong>Your order has been recorded.</strong></p>\n";
				foreach ($this->shoppingCart as $productID => $quantity) {
					//$this->product_id = $productID;
					$Row = $this->getProdInfo($productID);
							$instock = $Row['stock'] - $quantity;
							$desc = $Row['description'];
							$price = $Row['price'];
					if($quantity > 0 && isset($_SESSION['customerID'])){
						++$productOrdered;
						$IDorder = session_id();
						$SQLstring = "INSERT INTO orders (orderID, productID, customerID, quantity, orderdate) ".
						" VALUES('".$IDorder."', '$productID', '".$_SESSION['customerID']."', $quantity, '$date')";
						$QueryResult =
							$this->DBConnect->query($SQLstring);

							//update stock
							$this->updateStock($productID, $instock);	
							$this->orderReport($IDorder, $date, $desc, $quantity, $price);						
						//$product_id = $productID;
					}
					//echo "  ". $product_id;
				}
				//echo "<p>Thank you for Shopping</p>\n";
								
				
				//echo "<p>Please click here: <a href='#customer_report'>ORDER CONFIRMATION</a> for your order confirmation!<p>";
				if ($productOrdered == 0) {
						# code...
						echo "<p><strong>Please add Items to your cart</strong></p>";
					}

					if($productOrdered > 0 && isset($_SESSION['customerID'])){				
							
							if($QueryResult !== FALSE){
								$this->shoppingCart = array(); //empties array
								
								echo "<p><strong><h3>Your order has been recorded!</h3></strong></p>\n";
								//echo $this->shoppingCart[$productID];
								//$this->updateStock($productID);
							}
							else{
								echo "<p>Error occured while recording your order</p>\n";
							}					
					}else{
						echo "<p>Please Log In/Register to make a purchase!</p>";
					}
				}//end checkout

			public function orderReport($orderID, $dateOL, $description, $quantity, $price){

				$sqlstring = "INSERT INTO orderline(customerID, orderID, dateOL, description, quantity, price)".
						"VALUES('".$_SESSION['customerID']."','".$orderID."', '$dateOL', '$description', $quantity, '$price')";

						$queryresults = @$this->DBConnect->query($sqlstring);

						if($queryresults === FALSE)
							echo "<p>Error inserting into orderline table!</p>";

			/*	$SQLstring = "SELECT i.description, i.price, o.quantity, o.orderID, o.date FROM inventory i".
				"LEFT JOIN o.productID = i.productID";

				$QueryResult = @$this->DBConnect->query($SQLstring);

				if($QueryResult->num_rows == 0){
					echo "<p>No match found!</p>";
				}
				else{
					while ($row = $QueryResult->fetch_array()) {
						# code...
						$sqlstring = "INSERT INTO orderline(orderID, dateOL, description, quantity, price)".
						"VALUES(".$row['orderID'].", ".$row['orderdate'].", ".$row['description'].", ".$row['quantity'].", ".$row['price'].")";

						$queryresults = @$this->DBConnect->query($sqlstring);

						if($queryresults === FALSE)
							echo "<p>Error inserting into orderline table!</p>";
					}
				}

				

				if(count($this->inventory) > 0){
						foreach ($this->inventory as $ID => $Info) {

						}
					}*/
				
			}//end orderReport

			function invoice(){
				if(!isset($_SESSION['customerID'])){
			    	echo "<p><strong>Please Log In/Register to view History of purchase!</strong></p>";
			    	return FALSE;
			    }else{
			    	$sqlstring = "SELECT * FROM orderline WHERE customerID = '".$_SESSION['customerID']."'";

			    	$QueryResult = @$this->DBConnect->query($sqlstring);

			    	if($QueryResult->num_rows === 0){
			    		echo "<p>No Match Found!</p>";
			    	}else{
			    		echo "<table width='100%' border='1'>\n";			    		
			    		echo "<tr><th>Description</th><th>Price</th><th>Quantity</th></tr>\n";
			    		while ($row = $QueryResult->fetch_array()) {
			    			# code...
			    			echo "<tr>".$row['orderlineID']."</tr>\n";
			    			echo "<br>\n";
			    			echo "<tr>".$row['orderID']."</tr>\n";
			    			echo "<br>\n";
			    			echo "<tr>".$row['dateOL']."</tr>\n";
			    			echo "<br>\n";
			    			echo "<tr><td>".$row['description']."</td>\n";
			    			echo "<td>".$row['price']."</td>\n";
			    			echo "<td>".$row['quantity']."</td><tr>\n";
			    		}
			    		echo "</table>";
			    	}

			    }

			}			

			function user_exists($username){
				$username = sanitize($username);
				$Query = @mysql_query("SELECT COUNT('customerID') FROM customer WHERE username = '$username'");
				return (mysql_result($Query, 0)) ? TRUE : FALSE;
			}//end user_exists

			function get_user_Id($email){
				$email = sanitize($email);
				$this->email = $email;
				return mysql_result(mysql_query("SELECT customerID from customer WHERE username = '$email'"), 0, 'customerID');
			}//end get_user_Id

			function login($email, $password){
				$customerID = get_user_Id($email);

				$email = sanitize($email);
				$password = md5($password);

				return (mysql_result(mysql_query("SELECT COUNT(*) customerID FROM customer WHERE email = '$email' AND password = '$password'"), 0) == 1) ? $customerID : FALSE;

			}//end login

			function user_data($customerID){			

				$data = array();
				$customerID = (int)$customerID;

				$func_num_args = func_num_args();
				$func_get_args = func_get_args();

				

				if($func_num_args > 1){
					unset($func_get_args[0]);

					$fields = '`'.implode('`, `', $func_get_args).'`';
					//echo "SELECT '$fields' FROM `customer` WHERE `customerID` = $customerID";
					//die(mysql_error());
					$data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `customer` WHERE `customerID` = $customerID"));

					print_r($data);
					die(mysql_error());
					return $data;				
				}
			}

			function logged_in(){
				return (isset($_SESSION['customerID'])) ? TRUE : FALSE;
			}

			public function history()
			{
				if(!isset($_SESSION['customerID'])){
			    	echo "<p><strong>Please Log In/Register to view History of purchase!</strong></p>";
			    	return FALSE;
			    }

				$SQLstring = "SELECT * FROM orders" . 
			    " WHERE customerID='".$_SESSION['customerID']."'";

			    //$SQLstring = "SELECT c.firstName, c.lastName, c.customerID, o.orderdate, o.orderID, o.quantity FROM orders o JOIN customer c ON o.customerID = c.customerID WHERE c.customerID='".$_SESSION['customerID']."'";
			    $QueryResult = @$this->DBConnect->query($SQLstring);



			    if($QueryResult->num_rows === 0){
			    	echo "No Match Found";
			    }
			    else{
			    	echo "<p>Customer ID: ".$_SESSION['customerID']."</p>";
			    	echo "<table width='95%'>";
			    	echo "<tr><td>Order Id</td><td>Product ID</td><td>Date</td><td># of Items</td></tr>";
			    	while($row = $QueryResult->fetch_array()){
			    		echo "<tr><td>".$row['orderID']."</td>\n";
			    		echo "<td>".$row['productID']."</td>\n";
			    		echo "<td>".$row['orderdate']."</td>\n";
			    		echo "<td>".$row['quantity']."</td><tr>\n";
			    		/*echo "<p>\n <strong>:</strong> ".$row['orderID'].
			    		"\n <strong>: </strong>".$row['quantity'].
			    		"\n <strong>: </strong>".$row['orderdate']."\n\n<br /><br/></p>";*/
			    	}
			    	echo "</table>";
			    }	
			
			}
			
	}//end off class
?>